package com.op.parcel.manage.modules.sys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.op.parcel.common.constant.CommonConstant;
import com.op.parcel.common.utils.node.ForestNodeMerger;
import com.op.parcel.manage.modules.sys.entity.Permission;
import com.op.parcel.manage.modules.sys.mapper.PermissionMapper;
import com.op.parcel.manage.modules.sys.service.IPermissionService;
import com.op.parcel.manage.modules.sys.vo.PermissionVO;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 服务实现类
 *
 * @author xuan
 * @since 2019-01-09
 */
@Service
@AllArgsConstructor
public class PermissionServiceImpl extends ServiceImpl<PermissionMapper, Permission> implements IPermissionService {

	@Override
	public List<PermissionVO> tree(String id) {
		return ForestNodeMerger.merge(baseMapper.findMyPermission(id));
	}

	@Override
	public List<Permission> getInterfacePermissions() {
		Permission per = new Permission();
		QueryWrapper<Permission> permissionQueryWrapper = new QueryWrapper<>(per);
		permissionQueryWrapper.lambda()
			.eq(Permission::getType, CommonConstant.PERMISSION_INTERFACE)
			.eq(Permission::getStatus, CommonConstant.STATUS_NORMAL)
			.isNotNull(Permission::getTitle)
			.isNotNull(Permission::getPath);
		return baseMapper.selectList(permissionQueryWrapper);
	}
}
